package cn.yours.web.controller;

/**
 * 2024/6/10 13:01
 * wuhon
 * cn.yours.web.controller
 * file-elfinder
 */

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import java.io.FileWriter;
import java.io.IOException;

@RestController
public class SaveController {

    @PostMapping("/save")
    public String saveContent(@RequestBody ContentRequest contentRequest) {
        String filePath = "F:/file_location/TinyMCE5/saved_content.html";
        System.out.println("触发文件");
        try (FileWriter fileWriter = new FileWriter(filePath)) {
            fileWriter.write(contentRequest.getContent());
        } catch (IOException e) {
            e.printStackTrace();
            return "文件上传失败";
        }

        return "文件上传成功";
    }

    public static class ContentRequest {
        private String content;

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }
}
